package com.etime.shuhuiyuan.controllers.teacher;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.ListMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.pojo.Teacher;
import com.etime.shuhuiyuan.services.teacher.interfaces.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "teacher案例接口")
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("添加teacher案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="tectitle",value="教师title"),
            @ApiImplicitParam(name="tecdesc",value="教师简介"),
            @ApiImplicitParam(name="teclabel",value="教师技术标签"),
            @ApiImplicitParam(name="tecauditstate",value="教师审核状态,传递数字"),
            @ApiImplicitParam(name="tecauditopinion",value="教师审核意见"),
            @ApiImplicitParam(name="tecorgid",value="教师所属机构id,传递数字"),
            @ApiImplicitParam(name="tecbankname",value="教师银行开户行"),
            @ApiImplicitParam(name="lecbanknum",value="教师银行卡账户"),
            @ApiImplicitParam(name="tectakepoint",value="教师提成比例")
    })
    @GetMapping("/insert")
    public BaseMessage insertTeacher(Teacher teacher){
        BaseMessage msg = new BaseMessage();
        int rtn = teacherService.insertTeacher(teacher);
        msg.setCode(rtn);
        if (rtn > 0) {
            msg.setMsg("保存teacher成功");
        } else {
            msg.setMsg("保存teacher失败");
        }
        return msg;
    }

    @ApiOperation("修改teacher案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="tecid",value = "主键，必须传递"),
            @ApiImplicitParam(name="tectitle",value="教师title"),
            @ApiImplicitParam(name="tecdesc",value="教师简介"),
            @ApiImplicitParam(name="teclabel",value="教师技术标签"),
            @ApiImplicitParam(name="tecauditstate",value="教师审核状态,传递数字"),
            @ApiImplicitParam(name="tecauditopinion",value="教师审核意见"),
            @ApiImplicitParam(name="tecorgid",value="教师所属机构id,传递数字"),
            @ApiImplicitParam(name="tecbankname",value="教师银行开户行"),
            @ApiImplicitParam(name="lecbanknum",value="教师银行卡账户"),
            @ApiImplicitParam(name="tectakepoint",value="教师提成比例")
    })
    @GetMapping("/update")
    public BaseMessage updateTeacher(Teacher teacher){
        BaseMessage msg = new BaseMessage();
        int rtn = teacherService.updateTeacher(teacher);
        msg.setCode(rtn);
        if (rtn > 0) {
            msg.setMsg("保存teacher成功");
        } else {
            msg.setMsg("保存teacher失败");
        }
        return msg;
    }

    @ApiOperation("查询teacher列表案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tectitle", value = "传递字符串")
    })
    @GetMapping("/list")
    public ListMessage<Teacher> selectTeacherList(Teacher teacher){
        ListMessage<Teacher> listMessage = new ListMessage<>();
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        if (list != null) {
            listMessage.setDatalist(list);
            listMessage.setCode(1);
        } else {
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }

    @ApiOperation("分页查询teacher案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tecid", value = "传递数字"),
            @ApiImplicitParam(name = "tectitle", value = "通过职称查询"),
            @ApiImplicitParam(name = "pageNum", value = "第几页"),
            @ApiImplicitParam(name = "pageSize", value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<Teacher> selectTeacherByPage(Teacher teacher, Long pageNum, Long pageSize) {
        PageMessage<Teacher> msg = new PageMessage<>();
        Page<Teacher> pageData = teacherService.selectTeacherByPage(teacher, pageNum, pageSize);
        if (pageData != null) {
            msg.setCode(1);
            msg.setPagedata(pageData);
        } else {
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("根据id查询一条teacher信息的案例")
    @ApiImplicitParam("tecid")
    @GetMapping("/get/{tecid}")
    public PojoMessage<Teacher> selectTeacherById(@PathVariable("tecid") int tecid) {
        PojoMessage<Teacher> msg = new PojoMessage<>();
        Teacher teacher = teacherService.selectTeacherById(tecid);
        if (teacher != null) {
            msg.setCode(1);
            msg.setData(teacher);
        } else {
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }
}
